import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class HashMapTest {
    public static void main(String[] args) {
        Map<Person,String> map = new HashMap<>();
        map.put(new Person("zhangsan",22),"play basketball");
        map.put(new Person("lisi",34),"like play computer games");
        map.put(new Person("wangwu",44),"eat much");
        map.put(new Person("wangwu",44),"eat much22222");
        Set<Person> set = map.keySet();
        for (Person e: set) {
            System.out.println(e +"="+map.get(e));
        }

    }
}
class Person {
    String name;
    int age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

    @Override
    public String toString() {
        return "Person[" +
                "name='" + name + '\'' +
                ", age=" + age +
                ']';
    }
}